<template>
    <div>
      <commpVxeTable
        :key="reCommpVxeTable"
        :config="dataTableConfig"
        :columns="columnsVxe"
        :formItem="formItem"
        @checkboxChange="checkboxChange"
        ref="administrativeOffice"
        @searchEvent="searchEvent"
        @resetEvent="resetEvent"
        >
        <template v-slot:operation_fxm="{row}" data-desc="姓名">
            <span style="padding-right: 21;" v-if="row.fxm.length == 2">
                <span v-for="(trem,tI) in row.fxm.split('')" :key="tI" >
                    {{trem}}
                    <span v-if="tI+1 !== row.fxm.split('').length">&nbsp;&nbsp;</span>
                </span>
            </span>
            <span style="padding-right: 21;" v-else>{{ row.fxm }}</span>
        </template>
        <template v-slot:time1_btn="{row}" data-desc="出差开始时间">
              <span>
              {{ row.fccksrq +' '+ row.fcckssj }}
              </span>
          </template>
          <template v-slot:time2_btn="{row}" data-desc="出差结束时间">
              <span>
              {{ row.fccjsrq +' '+ row.fccjssj }}
              </span>
          </template>
        <template v-slot:operation_btn="{row}" data-desc="自定操作栏">
          <a-form layout="inline" class="search-form" >
              <a-form-item>
                  <a-button class="blue-btn" type="primary" @click="editHandele(row)">办理</a-button>
              </a-form-item>
          </a-form>
        </template>
      </commpVxeTable>
      <handleModal ref="handleModalRef" :formData="formData" :linkName="linkName" @success="success"></handleModal>
    </div>
  </template>
  <script>
  import assessCheckApi from './service/api.js'
  import commpVxeTable from '@/components/commp-vxe-table/commp-vxe-table.vue'
  import handleModal from '../index/applicationForm.vue'
  export default {
    components: {
      commpVxeTable,handleModal
    },
    props:{
      linkName:{
        type:String,
        default:'',
        required:false,
      }
    },
    data() {
      return {
        reCommpVxeTable: '',
        dataTableConfig: {
          api: assessCheckApi.list,
          rowId: 'joid',
          urlType: true,
          paramet:{
            fhjmc: this.linkName,
          }
        },
        columnsVxe: [
          {
            type: 'checkbox',
            width: 60,
            fixed: 'left'
          },{
            title: '姓名',
            field: 'fxm',
            width: 100,
            titleInterval:true,
            slots: {
                header:'data1_header',
                default:'operation_fxm',
            }
          },{
            title: '出差事由',
            field: 'fccsy',
          },{
            title: '出差开始日期',
            field: 'fccksrq',
            width: 150,
            slots: {
              default: 'time1_btn',
            },
          },{
            title: '出差结束日期',
            field: 'fccjsrq',
            width: 150,
            slots: {
              default: 'time2_btn',
            },
          },{
            title: '出差地点',
            field: 'fccdd',
          },{
            title: '填报时间',
            field: 'ftbsj',
          },{
            title: '操作',
            field: 'jobid',
            width: 100,
            titleInterval:true,
            slots: {
            // 使用插槽模板渲染
              header:'data2_header',
              default: 'operation_btn',
            },
          }
        ],
        formItem: [
          {
            label: '出差事由',
            model: 'fccsy',
          },
        ],
        joidList: [],
        formData: {},
      }
    },
    methods: {
      // 勾选
      checkboxChange(val){
        //console.log('已选择',val)
        this.joidList = []
        if(val.length){
          val.forEach(item => {
              this.joidList.push(item.joid)
          });
        }
      },
      // 搜索
      searchEvent(){
        this.dataTableConfig.paramet = {
            ...this.dataTableConfig.paramet,
        }
        //console.log(this.dataTableConfig.paramet)
      },
      // 重置
      resetEvent(){
        this.dataTableConfig.paramet = {
            ...this.dataTableConfig.paramet,
        }
      },
      // 编辑
      editHandele(row){
        //console.log(row)
        this.formData = {
            ...row,
            id: row.oaid
          }
          this.$nextTick(_ => {
              this.$refs.handleModalRef.applicationFormVisible = true
          })
      },
      // 弹窗提交成功
      success(){
        // 刷新表格 清空id数组
        this.$refs.administrativeOffice.searchEvent()
        this.joidList = []
      },
    },
  }
  </script>
    <style>
    @import url('../../css/oaClass.css');
    </style>
